using System;
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.ObjectBuilder;
using Jbe.TestSuite.Infrastructure.Interface;
using System.Diagnostics;
using Jbe.TestSuite.Infrastructure.Interface.Services;
using Microsoft.Practices.CompositeUI;

namespace Jbe.TestSuite.Message.Demo
{
    public partial class DemoView : UserControl, IDemoView
    {
        private IEditManager editManager;

        [ServiceDependency]
        public IEditManager EditManager
        {
            set 
            { 
                editManager = value;
                editManager.Register(messageText);
                editManager.Register(detailsText);
            }
        }

        public DemoView()
        {
            InitializeComponent();
            msgTypeCombo.SelectedIndex = 0;
        }

        protected override void OnLoad(EventArgs e)
        {
            presenter.OnViewReady();
            base.OnLoad(e);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                editManager.Deregister(messageText);
                editManager.Deregister(detailsText);

                if (presenter != null) { presenter.Dispose(); }
                if (components != null) { components.Dispose(); }
            }

            base.Dispose(disposing);
        }

        private void ShowDialogButtonClick(object sender, EventArgs e)
        {
            switch (msgTypeCombo.SelectedIndex)
            {
                case 0:
                    presenter.ShowInformationMessage(messageText.Text, detailsText.Text);
                    break;
                case 1:
                    presenter.ShowWarningMessage(messageText.Text, detailsText.Text);
                    break;
                case 2:
                    presenter.ShowErrorMessage(messageText.Text, detailsText.Text);
                    break;
                default:
                    Debug.Assert(false, "Default case is not allowed.");
                    break;
            }
        }

        private void ShowStatusBarButton(object sender, EventArgs e)
        {
            presenter.ShowStatusBar(messageText.Text);
        }

        private void ThrowExceptionButtonClick(object sender, EventArgs e)
        {
            presenter.ThrowException(DemoViewPresenter.ExceptionType.Exception);
        }
    }
}

